<?php

class BackupLocationsAddForm extends CFormModel
{
	public $id_backup_locations;
	public $name;
	public $protocol;
	public $server;
	public $username;
	public $password;
	public $port;
	public $directory;

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, protocol', 'required'),
//			array('server, username, password, port, directory', 'safe', 'on'=>'homedir'),
			array('server, username, password, port, directory', 'required', 'on'=>'not_homedir'),
			
			array('port', 'numerical', 'integerOnly'=>true),
			array('name, protocol, server, username, password, directory', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_backup_locations, name, protocol, server, username, password, port, directory', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_backup_locations' => t('info', 'Id Backup Locations'),
			'name' => t('info', 'Name'),
			'protocol' => t('info', 'Protocol'),
			'server' => t('info', 'Server (e.g. ftp.example.com)'),
			'username' => t('info', 'Username'),
			'password' => t('info', 'Password'),
			'port' => t('info', 'Port'),
			'directory' => t('info', 'Remote Directory (e.g. / )'),
		);
	}
	
	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}
	
	public function listProtocols()
	{
		return array(
			BackupLocations::PROTOCOL_HOMEDIR => t('info', 'Protocol') . ':　' . BackupLocations::PROTOCOL_HOMEDIR,
			BackupLocations::PROTOCOL_SCP => t('info', 'Protocol') . ':　' . BackupLocations::PROTOCOL_SCP,
			BackupLocations::PROTOCOL_FTP => t('info', 'Protocol') . ':　' . BackupLocations::PROTOCOL_FTP,
			BackupLocations::PROTOCOL_PASSIVEFTP => t('info', 'Protocol') . ':　' . BackupLocations::PROTOCOL_PASSIVEFTP
		);
	}
}